package
{
	import flash.display.MovieClip;
	import flash.display.Stage;
	import flash.net.URLVariables;

	public class StateClass extends State
	{
		protected var movieClip:MovieClip;
		protected var objects:Array = new Array();
		public function StateClass()
		{
			super();
		}
		/*
		public override function MouseClick(x:int, y:int):void
		{
			//buttons.MouseClick(x,y);
		}
		*/
		public override function MouseMove(x:int, y:int, buttonDown:Boolean):void
		{
			//buttons.MouseMove(x,y);
		}
		public override function ReceiveMessage(mess:String,param:Array,sender:MovieClip):void
		{
			switch(mess)
			{
				case "race_end":
					var httppost:FBHttpPost = new FBHttpPost(PostCallback);
					httppost.Post("state=class&m1=NewUser&classID="+param[0].toString()+"&spec="+param[1].toString());
					break;
			}
		}
		public override function Init():void
		{
			var s:Vector.<ExternalResource> = new Vector.<ExternalResource>();
			s.push(new ExternalResource("http://aagntw29.facebook.joyent.us/game/ClassSelect.swf",ExternalResource.movieClip));
			FBGame.stateStack.Push(new StateLoading(s,objects,this));
		}
		public override function LoadComplete(success:Boolean):void
		{
			if(success)
			{
				movieClip = objects[0];
				FBGame.mainFBGame.stage.addChild(movieClip);
			}
			else
			{
				FBGame.stateStack.Push(new StatePopup("Load ClassSelect.swf failed","OK"));
			}
		}
		public override function Release():void
		{
			FBGame.mainFBGame.stage.removeChild(movieClip);
		}
		public override function Render(g:MyGraphics):void
		{
			g.Clear(0xFF000000);
			//g.DrawMovieClip(0,0,buttons);
		}
		public function PostCallback(data:String,success:Boolean):void
		{
			if(success == false)
			{
				FBGame.stateStack.Push(new StatePopup(data,"OK"));
				return;
			}
			else
			{
				var variables:URLVariables = new URLVariables(data);
				if(variables.result == 0)
				{
					FBGame.stateStack.Pop();
					FBGame.stateStack.Push(new StateBattle(new Vector.<Unit>));
				}
				else
				{
					FBGame.stateStack.Push(new StatePopup("Failed: "+data,"OK"));
				}
			}
		}
	}
}